import java.io.*;
import java.lang.Object;
import java.util.*;
import de.vdheide.mp3.*;

public class Mp3Info {

private DBFile dbFile;
private TagContent albumTag;
private TagContent artistTag;
private TagContent musicLengthTag;
private TagContent genreTag;
private TagContent titleTag;
private MP3File mp3;

public Mp3Info(DBFile dbFile){
   this.dbFile = dbFile;
}

public void setMp3(){
   try{
      mp3 = new MP3File(dbFile.getPath());

      titleTag = mp3.getTitle();
      dbFile.setTitle2(titleTag.getTextContent());

      genreTag = mp3.getGenre();
      dbFile.setGenre(genreTag.getTextContent());
         if(dbFile.getGenre().endsWith(")")){
           dbFile.setGenre("");
         }

      artistTag = mp3.getArtist();
      dbFile.setArtist(artistTag.getTextContent());

      albumTag = mp3.getAlbum();
      dbFile.setAlbum(albumTag.getTextContent());

      musicLengthTag = mp3.getLengthInTag();
      String musicLength = musicLengthTag.getTextContent();
      Long len = new Long(musicLength);
      int time = len.intValue();
      dbFile.setMusicLength(formatTime(time));

      }
      catch(Exception e){}
}

public String formatTime(int mili){
    int togo = mili;
    int milis = togo%1000;
    togo /= 1000;
    int sec = togo%60;
    togo /= 60;
    int min = togo%60;
    Integer seconds = new Integer(sec);
    Integer minutes = new Integer(min);
    String duration = minutes.toString()+" min "+seconds.toString()+" sec";
    return duration;
 }

}



